const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const formatDate = times => {
  if (typeof times != 'number') {
    return
  } else {
    times = new Date(times);

    if (typeof times == 'number') {
      times = new Date(times)
    }

    var year = times.getFullYear()
    var month = times.getMonth() + 1
    var day = times.getDate()
    var hour = times.getHours()
    var minute = times.getMinutes()
    var second = times.getSeconds()

    return year + '-' + formatNumber(month) + '-' + formatNumber(day);
  }
}

module.exports = {
  formatTime: formatTime,
  formatDate: formatDate
}
